package edu.upf.opencities.web.connector.impl;

import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.log4j.Logger;

public class ConnectorBooleanImpl {

	private static ConnectorBooleanImpl connector = null;
	public static Logger logger = Logger.getLogger(ConnectorImpl.class);

	public static synchronized ConnectorBooleanImpl getInstace() {
		if (null == connector) {
			connector = new ConnectorBooleanImpl();
		}
		return connector;
	}

	public boolean executeBoolean(String command, String type) {
		URL url = null;
		HttpURLConnection uc = null;
		
		try{
			url = new URL(command.replace(" ", "%20"));
			if (logger.isTraceEnabled()) {
				logger.trace("Sending message to: " + command);
			}
	
			uc = (HttpURLConnection) url.openConnection();
			uc.setRequestMethod(type);
			uc.setRequestProperty("Content-Type", "application/xml");
			uc.setRequestProperty("Accept", "application/xml");
	
			if(200 == uc.getResponseCode()){
				return true;
			}
			else{
				return false;
			}
			
		}catch(Exception e){return false;}
	}
}
			
